/**
 * v-auth
 * 按钮权限指令
 */
import { useAuthStore } from "@/stores/modules/auth";
import type { Directive, DirectiveBinding } from "vue";

const auth: Directive = {
  mounted(el: HTMLElement, binding: DirectiveBinding) {
    const { value } = binding;
    const authStore = useAuthStore();
    const currentPageButtons = authStore.authButtonListGet[authStore.routeName] ?? [];
    if (!currentPageButtons.some(x => x.perms === value)) el.remove(); // 如果当前用户当前页面无此按钮权限则移除该按钮
  }
};

export default auth;
